package cn.myzqu.sign.project.server.api;


import cn.myzqu.sign.common.response.ResultData;
import cn.myzqu.sign.project.client.ProjectStaffClient;
import cn.myzqu.sign.project.common.input.ProjectStaffInput;
import cn.myzqu.sign.project.server.entity.ProjectStaff;
import cn.myzqu.sign.project.server.service.ProjectStaffService;
import cn.myzqu.sign.project.server.utils.TokenUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;

/**
 * @Author: 的川
 * @Date: 2019/3/5 19:48
 */
@RestController
public class ProjectStaffApi implements ProjectStaffClient {

    @Autowired
    private ProjectStaffService projectStaffService;


    @ApiOperation("报名参与项目")
    @Override
    public ResultData apply(@RequestBody ProjectStaffInput staffInput) throws Exception{
        String loginId = TokenUtil.getUserId();
        staffInput.setUserId(loginId);
        ProjectStaff projectStaff = new ProjectStaff();
        BeanUtils.copyProperties(staffInput,projectStaff);
        if(projectStaffService.add(projectStaff)){
            return ResultData.success();
        }
        return ResultData.error("报名失败！");
    }

    @ApiOperation("获取项目人员列表")
    @Override
    public ResultData search(@RequestBody Map params){

        List<Map> result = projectStaffService.search(params);
        if(result!=null && result.size()>0){
            return ResultData.success(result);
        }
        return ResultData.error("查无结果！");

    }
}
